package com.tangding.controller.subpage;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.tangding.common.exception.GException;
import com.tangding.common.holder.SpringContextHolder;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年11月15日_下午1:06:19
 *
 */
@RestController
public class PageController {
	
	@RequestMapping("/*.html")
	public ModelAndView page(HttpServletRequest request, 
			@RequestParam(value = "operate", required = false) String operate,
			@RequestParam(value = "param", required = false) String params) throws GException {
		String uri = request.getRequestURI();
		ModelAndView view = new ModelAndView();
		ContentProcessor processor = SpringContextHolder.getBean(uri);
		if (processor != null) {
			processor.doProcess(view, operate, params);
		}
		uri = uri.substring(1, uri.lastIndexOf("."));
		view.setViewName(uri);
		return view;
	}
	
	@RequestMapping("subpage/{model}/*.html")
	public ModelAndView sub(HttpServletRequest request, 
			@RequestParam(value = "operate", required = false) String operate,
			@RequestParam(value = "param", required = false) String params) throws GException {
		String uri = request.getRequestURI();
		ModelAndView view = new ModelAndView();
		ContentProcessor processor = SpringContextHolder.getBean(uri);
		if (processor != null) {
			processor.doProcess(view, operate, params);
		}
		uri = uri.substring(1, uri.lastIndexOf("."));
		view.setViewName(uri);
		return view;
	}
}
